﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using OVS.Business;
using OVS.CoreDomain.Business;
using OVS.CoreDomain;

namespace OVS.UserControl
{
    public partial class SelectWard : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
                FillDistrictDropDown();
        }

        protected void FillDistrictDropDown()
        {
            ddlDistrict.Items.Clear();
            IBusinessDistrict businessDistrict = new BusinessDistrict();
            ddlDistrict.DataValueField = "DistrictId";
            ddlDistrict.DataTextField = "DistrictName";
            ddlDistrict.DataSource = businessDistrict.GetDistricts();
            ddlDistrict.DataBind();
            ddlDistrict.Items.Insert(0, "Select");
        }
        protected void ddlDistrict_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            FillPanchayat(ddlDistrict.SelectedValue);
        }

        public void FillPanchayat(string districtId)
        {
            ddlPanchayat.Items.Clear();
            IBusinessPanchayat businessPanchayat = new BusinessPanchayat();
            ddlPanchayat.DataValueField = "PanchayatId";
            ddlPanchayat.DataTextField = "PanchayatName";
            ddlPanchayat.DataSource = businessPanchayat.GetPanchayats(districtId);
            ddlPanchayat.DataBind();
            ddlPanchayat.Items.Insert(0, "Select");
        }
        protected void ddlPanchayat_OnSelectedIndexChanged(object sender, EventArgs e)
        {

            FillWards(ddlPanchayat.SelectedValue);
        }

        public void FillWards(string wardId)
        {
            ddlWard.Items.Clear();
            IBusinessWard businessWard = new BusinessWard();
            ddlWard.DataValueField = "WardId";
            ddlWard.DataTextField = "WardName";
            ddlWard.DataSource = businessWard.GetWards(wardId);
            ddlWard.DataBind();
            ddlWard.Items.Insert(0, "Select");
        }
    }
}